import { Camera, Scene, WebGLRenderer } from 'three';
import { _SceneManager } from '.';
import { _Config } from './Config';

class Renderer {
  private renderer!: WebGLRenderer;
  private scene!: Scene;
  private camera!: Camera;

  private dirty = false;
  init(renderer: WebGLRenderer, scene: Scene, camera: Camera) {
    this.scene = scene;
    this.camera = camera;
    this.renderer = renderer;
    this.dirty = false;
    _SceneManager.addResizeEvent('Render', () => {
      this.renderer.setSize(_Config.width, _Config.height);
    });
  }

  render = () => {
    if (this.dirty) {
      this.renderer.render(this.scene, this.camera);
      //this.dirty = false;
    }
  };
  setDirty() {
    this.dirty = true;
  }
}

export const _Renderer = new Renderer();
